package reamodel.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

import reamodel.ReamodelPackage;
import reamodel.diagram.part.REAmetamodelDiagramEditorPlugin;

/**
 * @generated
 */
public class REAmetamodelElementTypes extends ElementInitializers {

	/**
	 * @generated
	 */
	private REAmetamodelElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType REAModel_79 = getElementType("REAModeller.diagram.REAModel_79"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EconomicResourceType_1001 = getElementType("REAModeller.diagram.EconomicResourceType_1001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EconomicAgentType_1002 = getElementType("REAModeller.diagram.EconomicAgentType_1002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DecrementEconomicEventType_1003 = getElementType("REAModeller.diagram.DecrementEconomicEventType_1003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementEconomicEventType_1004 = getElementType("REAModeller.diagram.IncrementEconomicEventType_1004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EconomicAgent_1005 = getElementType("REAModeller.diagram.EconomicAgent_1005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EconomicResource_1006 = getElementType("REAModeller.diagram.EconomicResource_1006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DecrementEconomicEvent_1007 = getElementType("REAModeller.diagram.DecrementEconomicEvent_1007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementEconomicEvent_1008 = getElementType("REAModeller.diagram.IncrementEconomicEvent_1008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementCommitment_1009 = getElementType("REAModeller.diagram.IncrementCommitment_1009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DecrementCommitment_1010 = getElementType("REAModeller.diagram.DecrementCommitment_1010"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EconomicResourceTypeTypify_3001 = getElementType("REAModeller.diagram.EconomicResourceTypeTypify_3001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Outflow_3002 = getElementType("REAModeller.diagram.Outflow_3002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Inflow_3003 = getElementType("REAModeller.diagram.Inflow_3003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DecrementEconomicEventTypeTypify_3004 = getElementType("REAModeller.diagram.DecrementEconomicEventTypeTypify_3004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementEconomicEventTypeTypify_3005 = getElementType("REAModeller.diagram.IncrementEconomicEventTypeTypify_3005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType OutflowType_3006 = getElementType("REAModeller.diagram.OutflowType_3006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType InflowType_3007 = getElementType("REAModeller.diagram.InflowType_3007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EconomicAgentTypeTypify_3008 = getElementType("REAModeller.diagram.EconomicAgentTypeTypify_3008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ReceiveParticipation_3009 = getElementType("REAModeller.diagram.ReceiveParticipation_3009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ProvideParticipation_3010 = getElementType("REAModeller.diagram.ProvideParticipation_3010"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementEconomicEventDuality_3011 = getElementType("REAModeller.diagram.IncrementEconomicEventDuality_3011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementEconomicEventTypeDualityType_3012 = getElementType("REAModeller.diagram.IncrementEconomicEventTypeDualityType_3012"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType CommitmentAgent_3013 = getElementType("REAModeller.diagram.CommitmentAgent_3013"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType CommitmentResource_3014 = getElementType("REAModeller.diagram.CommitmentResource_3014"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementCommitmentFulfill_3015 = getElementType("REAModeller.diagram.IncrementCommitmentFulfill_3015"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DecrementCommitmentFulfill_3016 = getElementType("REAModeller.diagram.DecrementCommitmentFulfill_3016"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementCommitmentReciprocity_3017 = getElementType("REAModeller.diagram.IncrementCommitmentReciprocity_3017"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType DecrementCommitmentSpecify_3018 = getElementType("REAModeller.diagram.DecrementCommitmentSpecify_3018"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType IncrementCommitmentSpecify_3019 = getElementType("REAModeller.diagram.IncrementCommitmentSpecify_3019"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return REAmetamodelDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap();

			elements.put(REAModel_79, ReamodelPackage.eINSTANCE.getREAModel());

			elements.put(EconomicResourceType_1001, ReamodelPackage.eINSTANCE
					.getEconomicResourceType());

			elements.put(EconomicAgentType_1002, ReamodelPackage.eINSTANCE
					.getEconomicAgentType());

			elements.put(DecrementEconomicEventType_1003,
					ReamodelPackage.eINSTANCE.getDecrementEconomicEventType());

			elements.put(IncrementEconomicEventType_1004,
					ReamodelPackage.eINSTANCE.getIncrementEconomicEventType());

			elements.put(EconomicAgent_1005, ReamodelPackage.eINSTANCE
					.getEconomicAgent());

			elements.put(EconomicResource_1006, ReamodelPackage.eINSTANCE
					.getEconomicResource());

			elements.put(DecrementEconomicEvent_1007, ReamodelPackage.eINSTANCE
					.getDecrementEconomicEvent());

			elements.put(IncrementEconomicEvent_1008, ReamodelPackage.eINSTANCE
					.getIncrementEconomicEvent());

			elements.put(IncrementCommitment_1009, ReamodelPackage.eINSTANCE
					.getIncrementCommitment());

			elements.put(DecrementCommitment_1010, ReamodelPackage.eINSTANCE
					.getDecrementCommitment());

			elements.put(EconomicResourceTypeTypify_3001,
					ReamodelPackage.eINSTANCE.getEconomicResourceType_Typify());

			elements.put(Outflow_3002, ReamodelPackage.eINSTANCE.getOutflow());

			elements.put(Inflow_3003, ReamodelPackage.eINSTANCE.getInflow());

			elements.put(DecrementEconomicEventTypeTypify_3004,
					ReamodelPackage.eINSTANCE
							.getDecrementEconomicEventType_Typify());

			elements.put(IncrementEconomicEventTypeTypify_3005,
					ReamodelPackage.eINSTANCE
							.getIncrementEconomicEventType_Typify());

			elements.put(OutflowType_3006, ReamodelPackage.eINSTANCE
					.getOutflowType());

			elements.put(InflowType_3007, ReamodelPackage.eINSTANCE
					.getInflowType());

			elements.put(EconomicAgentTypeTypify_3008,
					ReamodelPackage.eINSTANCE.getEconomicAgentType_Typify());

			elements.put(ReceiveParticipation_3009, ReamodelPackage.eINSTANCE
					.getReceiveParticipation());

			elements.put(ProvideParticipation_3010, ReamodelPackage.eINSTANCE
					.getProvideParticipation());

			elements.put(IncrementEconomicEventDuality_3011,
					ReamodelPackage.eINSTANCE
							.getIncrementEconomicEvent_Duality());

			elements.put(IncrementEconomicEventTypeDualityType_3012,
					ReamodelPackage.eINSTANCE
							.getIncrementEconomicEventType_DualityType());

			elements.put(CommitmentAgent_3013, ReamodelPackage.eINSTANCE
					.getCommitment_Agent());

			elements.put(CommitmentResource_3014, ReamodelPackage.eINSTANCE
					.getCommitment_Resource());

			elements.put(IncrementCommitmentFulfill_3015,
					ReamodelPackage.eINSTANCE.getIncrementCommitment_Fulfill());

			elements.put(DecrementCommitmentFulfill_3016,
					ReamodelPackage.eINSTANCE.getDecrementCommitment_Fulfill());

			elements.put(IncrementCommitmentReciprocity_3017,
					ReamodelPackage.eINSTANCE
							.getIncrementCommitment_Reciprocity());

			elements.put(DecrementCommitmentSpecify_3018,
					ReamodelPackage.eINSTANCE.getDecrementCommitment_Specify());

			elements.put(IncrementCommitmentSpecify_3019,
					ReamodelPackage.eINSTANCE.getIncrementCommitment_Specify());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet();
			KNOWN_ELEMENT_TYPES.add(REAModel_79);
			KNOWN_ELEMENT_TYPES.add(EconomicResourceType_1001);
			KNOWN_ELEMENT_TYPES.add(EconomicAgentType_1002);
			KNOWN_ELEMENT_TYPES.add(DecrementEconomicEventType_1003);
			KNOWN_ELEMENT_TYPES.add(IncrementEconomicEventType_1004);
			KNOWN_ELEMENT_TYPES.add(EconomicAgent_1005);
			KNOWN_ELEMENT_TYPES.add(EconomicResource_1006);
			KNOWN_ELEMENT_TYPES.add(DecrementEconomicEvent_1007);
			KNOWN_ELEMENT_TYPES.add(IncrementEconomicEvent_1008);
			KNOWN_ELEMENT_TYPES.add(IncrementCommitment_1009);
			KNOWN_ELEMENT_TYPES.add(DecrementCommitment_1010);
			KNOWN_ELEMENT_TYPES.add(EconomicResourceTypeTypify_3001);
			KNOWN_ELEMENT_TYPES.add(Outflow_3002);
			KNOWN_ELEMENT_TYPES.add(Inflow_3003);
			KNOWN_ELEMENT_TYPES.add(DecrementEconomicEventTypeTypify_3004);
			KNOWN_ELEMENT_TYPES.add(IncrementEconomicEventTypeTypify_3005);
			KNOWN_ELEMENT_TYPES.add(OutflowType_3006);
			KNOWN_ELEMENT_TYPES.add(InflowType_3007);
			KNOWN_ELEMENT_TYPES.add(EconomicAgentTypeTypify_3008);
			KNOWN_ELEMENT_TYPES.add(ReceiveParticipation_3009);
			KNOWN_ELEMENT_TYPES.add(ProvideParticipation_3010);
			KNOWN_ELEMENT_TYPES.add(IncrementEconomicEventDuality_3011);
			KNOWN_ELEMENT_TYPES.add(IncrementEconomicEventTypeDualityType_3012);
			KNOWN_ELEMENT_TYPES.add(CommitmentAgent_3013);
			KNOWN_ELEMENT_TYPES.add(CommitmentResource_3014);
			KNOWN_ELEMENT_TYPES.add(IncrementCommitmentFulfill_3015);
			KNOWN_ELEMENT_TYPES.add(DecrementCommitmentFulfill_3016);
			KNOWN_ELEMENT_TYPES.add(IncrementCommitmentReciprocity_3017);
			KNOWN_ELEMENT_TYPES.add(DecrementCommitmentSpecify_3018);
			KNOWN_ELEMENT_TYPES.add(IncrementCommitmentSpecify_3019);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

}
